<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <h1>关总你好</h1>
    <p id="severtime"></p>
    <script>
        getsevertime();

        function getsevertime(option) {
            var xhr = null;
            if (window.XMLHttpRequest) {
                xhr = new XMLHttpRequest();
            } else { 
                xhr = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xhr.open('GET', '/', true);
            xhr.send(null);
            xhr.onreadystatechange = function () {
                var time = null,
                    curDate = null;
                //if (xhr.readyState === 2 || xhr.readyState === 4) {
                    console.log(xhr.readyState);
                        //console.log(xhr.getAllResponseHeaders());
                        time = xhr.getResponseHeader("Date");
                        curDate = new Date(time);
                        console.log(curDate);
                        document.getElementById("severtime").innerHTML = "服务器时间是：" + curDate.getFullYear() + "-" + (curDate
                            .getMonth() + 1) + "-" + curDate.getDate() + " " + curDate.getHours() + ":" + curDate
                        .getMinutes() + ":" + curDate.getSeconds();
                //}
            }
        }
        
        setInterval(getsevertime, 1000);
    </script>
</body>

</html>